Ext.onReady(function(){

    //Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

    // create some portlet tools using built in Ext tool ids
    var tools = [{
        id:'gear',
        handler: function(){
            Ext.Msg.alert('Message', 'The Settings tool was clicked.');
        }
    },{
        id:'close',
        handler: function(e, target, panel){
            panel.ownerCt.remove(panel, true);
        }
    }];
    
    var requestTypeStore = new Ext.data.JsonStore({
    	fields:['codeValue','codeType','codeDesc','positionNo','status']
    });
    
    var requestTypeCombo = new Ext.form.ComboBox( {
        typeAhead : true,
        store:requestTypeStore,
        mode:'local',
        allowBlank :true,
        typeAhead :true,
        triggerAction : 'all',
        emptyText: '请选择...',
        valueField:'codeValue',
        displayField:'codeDesc',
        width : 135,      
        fieldLabel : '需求种类',
        hiddenName :'requestType',
        resizable:true,
        anchor : '70%' // anchor width by percentage
    });
    
    var formPanel = new Ext.form.FormPanel({
		frame : true,
		bodyStyle : 'padding:5px 5px 0',
		labelWidth : 120, 
		autoScroll:true,
		defaults :{labelSeparator :''},
		items : [{
			layout : 'column',
			items : [{
				columnWidth : .5,
				layout : 'form',
				defaults :{labelSeparator :''},
				items : [{
					xtype : 'textfield',
					fieldLabel : '申请人',
					name : 'applerName',
					anchor : '70%',
					readOnly :true
				}, {
					xtype : 'textfield',					
					fieldLabel : '申请人部门',
					name : 'applerDeptName',
					anchor : '70%',
					readOnly :true
				},requestTypeCombo, {
					xtype : 'textfield',
					fieldLabel : '工作地点',
					name : 'workPlace',
					anchor : '70%'
				}]
			}, {
				columnWidth : .5,
				layout : 'form',
				defaults :{labelSeparator :''},
				items : [{
					xtype : 'textfield',
					fieldLabel : '提交人',
					name : 'commitorName',
					anchor : '70%',
					readOnly :true
				}, {
					xtype : 'numberfield',
					fieldLabel : '申请人联系电话/分机',
					name : 'tel',
					anchor : '70%'
				}]
			}]
		}, {
			xtype : 'textarea',
			fieldLabel : '用户服务需求描述',
			name : 'purpose',
			height : 60, 
			anchor : '85%'
		}, {
			layout : 'column',
			items : [{
				columnWidth : .5,
				layout : 'form',
				defaults :{labelSeparator :''},
				items : [{
					xtype : 'datefield',
					fieldLabel : '需求提出时间',
					format  : 'Y-m-d H:i:s', 
					name : 'applyDateTime',
					anchor : '70%'
				}]
			}, {
				columnWidth : .5,
				layout : 'form',
				defaults :{labelSeparator :''},
				items : [{
					xtype : 'datefield',
					fieldLabel : '希望完成时间',
					format  : 'Y-m-d H:i:s', 
					name : 'endDateTime',
					anchor : '70%'
				}]
			}]
		},{
			xtype:'hidden',
			name:'applerId'
		},{
			xtype:'hidden',
			name:'applerDeptId'
		},{
			xtype:'hidden',
			name:'commitorId'
		},{
			xtype:'hidden',
			name:'bizCode'
		}]
	});
    
    var action = {
		title : '工作流处理',
		tools : tools,	
		autoScroll:true,
		height: 70,
		items:[{
			text : '提交',
			columnWidth: .25,
			xtype:'button',
			handler : function(){
				var obj = this.getForm().getValues();
				Ext.apply(obj,commandBaseParam);
				//调用dwr函数
				ItFacilityApplyFacade.commitTask(obj,function(data){
					alert(data);
				});
				
			}.createDelegate(formPanel)
		}, {
			columnWidth: .25,
			xtype:'button',
			text : '保存'
		}]
	};
    
	var columnPanel = new Ext.form.FormPanel({
		title: 'Column Layout',
	    bodyStyle:'padding:5px',
		defaults: {bodyStyle:'padding:15px'},
	    items: [{
	    	layout:'column',
	    	items:[{
	    		columnWidth: .25,
	    		xtype:'button',
				text : '保存'
	    	},{
	    		columnWidth: .25,
	    		xtype:'button',
				text : '保存'
	    	}]
	    }]
	});
	var viewport = new Ext.Viewport({
			layout : 'border',
			items : [{
				xtype : 'portal',
				region : 'center',
				margins : '0 0 0 0',
				items : [{
					columnWidth : .98,
					style : 'padding:10px 0 10px 10px',
					items : [ {
						title : '信息设备申请',
						layout : 'fit',
						tools : tools,
						height : 500,
						items : formPanel
					}]
				}]
			}]
		});
    //加载form的数据
    //获取url中的参数
    /*var url = this.document.location.href;
    var param = url.substr(url.lastIndexOf('?')+1);
    var searchObj = Ext.urlDecode(param);
    
    var commandBaseParam =null;
    //调用dwr的函数
    ItFacilityApplyFacade.beforeInitData(searchObj,function(data){
    	//创建record
    	var FormRecord = Ext.data.Record.create([
	    	{name:'applerName'},
	    	{name:'applerId'},
	    	{name:'applerDeptName'},
	    	{name:'applerDeptId'},
	    	{name:'requestType'},
	    	{name:'workPlace'},
	    	{name:'commitorName'},
	    	{name:'commitorId'},
	    	{name:'tel'},
	    	{name:'purpose'},
	    	{name:'applyDateTime'},
	    	{name:'endDateTime'},
	    	{name:'bizCode'}
	    ]);
	    //实例化一个创建好的record类
   		var formRecord =  new FormRecord(data.itApply);
   		commandBaseParam = data.commandBaseParam;
   		//加载下拉框的数据
   		requestTypeStore.loadData(data.requestType);
   		
   		//加载表单数据
    	//this.getForm().loadRecord(formRecord);
    	
    	//判断是否是提交人
    	action.items.add([{
    		xtype:'button',
    		text : '推出任务'
    	},{
    		xtype:'button',
    		text : '驳回到'
    	},{
    		xtype:'combo',
    		emptyText: '请选择...'
    	}]);
    	
    	var viewport = new Ext.Viewport({
			layout : 'border',
			items : [{
				xtype : 'portal',
				region : 'center',
				margins : '0 0 0 0',
				items : [{
					columnWidth : .98,
					style : 'padding:10px 0 10px 10px',
					items : [action, {
						title : '信息设备申请',
						layout : 'fit',
						tools : tools,
						height : 500,
						items : formPanel
					}, columnPanel]
				}]
			}]
		});
    	
    }.createDelegate(formPanel));*/
    
    
});